package JAVA300.第十二章WebServer;

import java.lang.reflect.InvocationTargetException;

/**
 * 反射基本知识学习
 */
public class server1_basic {
    public static void main(String[] args) {

        //1 获取class
        //法1-对象.getClass（）==学习工程师技术设计phone
        Class clz = new Phone().getClass();
        //法2-类.class==贿赂工程师让他设计图纸
        Class clz1 = Phone.class;
        //法2-Class.forName(包名.类名)==定位图纸位置，直接偷
        Class clz2;

        {
            try {
                clz2 = Class.forName("JAVA300.第十二章WebServer.Phone");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }


        //2创建对象
        //法1--利用newInstance方法--在JDK9淘汰了
        //法2--构造器
        Phone p1,p2;

        {
            try {
                p1 = (Phone)clz.newInstance();
                p2 = (Phone)clz1.getConstructor().newInstance();
                System.out.println(p1);
                System.out.println(p2);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException | NoSuchMethodException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }

    }



}

class Phone{
    public Phone() {
    }
}
